package com.gzist.springailab06.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.openai.OpenAiAudioSpeechModel;
import org.springframework.ai.openai.OpenAiAudioSpeechOptions;
import org.springframework.ai.openai.api.OpenAiAudioApi;
import org.springframework.ai.openai.audio.speech.SpeechPrompt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ai文本转语音测试接口
 */
@RestController
@RequestMapping("/springAi")
@RequiredArgsConstructor
public class AudioController {

    private final OpenAiAudioSpeechModel openAiAudioSpeechModel;

    @GetMapping("/textToVoice")
    public Object textToVoice(@RequestParam("需要转换的文本") String msg) {
        OpenAiAudioSpeechOptions speechOptions = OpenAiAudioSpeechOptions.builder()
                .voice(OpenAiAudioApi.SpeechRequest.Voice.ALLOY)
                .responseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
                .speed(1.0f)
                .build();
        return openAiAudioSpeechModel.call(new SpeechPrompt(msg,speechOptions)).getResult();
    }
}
